package edu.qut.demo.mvc.action;

import edu.qut.demo.service.IDemoService;
import edu.qut.mvcframework.annotation.MyAutowired;
import edu.qut.mvcframework.annotation.MyController;
import edu.qut.mvcframework.annotation.MyRequestMapping;
import edu.qut.mvcframework.annotation.MyRequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author: lcl1024
 * @Description:
 * @Date: Created in 11:03 2019-07-11
 * @Modified By:
 */

@MyController
@MyRequestMapping("/demo")
public class DemoAction {
    @MyAutowired
    private IDemoService demoService;

    @MyRequestMapping("/query.json")
    public void query(HttpServletRequest req, HttpServletResponse resp,
                      @MyRequestParam("name") String name) {
        String result = demoService.get(name);
        try {
            resp.getWriter().write(result);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @MyRequestMapping("/add.json")
    public void add(HttpServletRequest req, HttpServletResponse resp,
                    @MyRequestParam("a") Integer a,@MyRequestParam("b") Integer b) {
        try{
            resp.getWriter().write(a + "+" + b + "=" + (a + b));
        }catch (IOException e) {
            e.printStackTrace();;
        }
    }

    @MyRequestMapping("/remove.json")
    public void remove(HttpServletRequest req,HttpServletResponse resp,
                       @MyRequestParam("id") Integer id) {

    }


}
